package com.badlogic.androidgames;

import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.IOException;

import android.app.Activity;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.os.Environment;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.TextView;

public class SoundPoolTest extends Activity implements OnTouchListener {
	SoundPool soundPool;
	int explosionId = -1;
	TextView textView ;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		textView=new TextView(this);
		textView.setOnTouchListener(this);
		setContentView(textView);
		setVolumeControlStream(AudioManager.STREAM_MUSIC);
		soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
//		try {
//			AssetManager assetManager = getAssets();
			
//			AssetFileDescriptor descriptor = assetManager
//					.openFd("1.mp3");
			String path=Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"download"+File.separator+"Love.mp3";
			textView.setText(path);
			explosionId = soundPool.load(path,1);
//			FileDescriptor f=new FileInputStream(path).getFD();
//			soundPool.l
			textView.setText("playing");
//		} catch (IOException e) {
//			textView.setText("Couldn't load sound effect from asset, "
//					+ e.getMessage());
//		}
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_UP) {
			if (explosionId != -1) {
				soundPool.play(explosionId, 1, 1, 0, 0, 1);
				textView.setText("playing....");
			}
		}
		return true;
	}
}